package com.example.innovate.service.impl;

import com.example.innovate.domain.ResumeDO;
import com.example.innovate.domain.ResumeDOExample;
import com.example.innovate.mapper.ResumeDOMapper;
import com.example.innovate.service.ResumeService;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ResumeServiceImpl implements ResumeService {
    @Autowired
    ResumeDOMapper resumeDOMapper;

    @Override
    public ResumeDO addInfo(ResumeDO resumeDO) {
        resumeDOMapper.insertSelective(resumeDO);
        return resumeDO;
    }

    @Override
    public void deleteInfo(int id) {
        resumeDOMapper.deleteByPrimaryKey(id);
    }

    @Override
    public ResumeDO updateInfo(ResumeDO resumeDO) {
        resumeDOMapper.updateByPrimaryKeySelective(resumeDO);
        return resumeDO;
    }

    @Override
    public List<ResumeDO> findInfo(int pageNumber, int pageSize,int userId) {
        ResumeDOExample resumeDOExample = new ResumeDOExample();
        if(userId!=0){
            resumeDOExample.createCriteria()
                    .andReUserIdEqualTo(userId);
        }
        PageHelper.startPage(pageNumber,pageSize);
        return resumeDOMapper.selectByExample(resumeDOExample);
    }

    @Override
    public ResumeDO findById(int id) {
        return resumeDOMapper.selectByPrimaryKey(id);
    }
}
